<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <UpgradeRecordSetRemarkDrawer @register="registerUpgradeRecordSetRemarkDrawer" @success="handleSuccess"></UpgradeRecordSetRemarkDrawer>
  </div>
</template>
<script lang="ts" setup name="upgradeRecord">
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/table';
import UpgradeRecordSetRemarkDrawer from './components/UpgradeRecordSetRemarkDrawer.vue';
import { columns, searchFormSchema } from './data';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import { Api } from './api';

const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'upgradeRecord-template',
  tableProps: {
    //表格标题
    title: '升降卡记录列表',
    //主键字段
    rowKey: 'upgradeRecordId',
    //列表接口
    listUrl: Api.page,
    //列表查询handler
    handlerName: 'busUpgradeRecordListHandler',
    //删除接口
    delUrl: Api.remove,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      showExportButton: true,
    },
    //操作列配置
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    //查询前处理
    beforeFetch: params => {
      params.newAirportIds = '';
      let newAirportIdArray: any = params.newAirportIdArray;
      console.info('--------------beforeFetch-------newAirportIdArray--------------------------', newAirportIdArray);
      if (newAirportIdArray) {
        params.newAirportIds = newAirportIdArray.join(',');
      }
      delete params.newAirportIdArray;
      let oldGoodsIdArray: any = params.oldGoodsIdArray;
      console.info('--------------beforeFetch-------oldGoodsIdArray--------------------------', oldGoodsIdArray);
      if (oldGoodsIdArray) {
        params.oldGoodsIds = oldGoodsIdArray.join(',');
      }
      delete params.oldGoodsIdArray;
      return params;
    },
  },
});

const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

const [registerUpgradeRecordSetRemarkDrawer, { openDrawer: openUpgradeRecordSetRemarkDrawer }] = useDrawer();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '设置备注',
      onClick: handlerSetRemark.bind(null, record),
      auth: 'ACTION_upgradeRecordSetRemark',
    },
  ];
}

function handlerSetRemark(record) {
  openUpgradeRecordSetRemarkDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
